import java.util.ArrayList;

public class Team 
{
  private int id;
  private String name;
  private ArrayList <Player> squad;
  private PlayingSide side;
  private Manager manager;

  public Team (int id, String name, Player [] squad, Manager manager)
  {
    this.id = id;
    this.name = name;
    this.squad = new ArrayList <Player> (squad.length);

    for (int i = 0; i < squad.length; i++){
      this.squad.add(squad[i]);
    }

    this.manager = manager;
  }

  public void set_formation (PlayingPosition [] formation)
  {
    side.set_formation(formation);
  }

  public void set_position (Player player, PlayingPosition position) throws PlayerSelectionException
  {
    check_player(player);
    side.set_position(player,position);
  } 

  private void check_player (Player player) throws PlayerSelectionException
  {
    boolean found = false;
    for (int i=0; i < squad.size(); i++){
      if (player.equals(squad.get(i))){
        found = true;
        break;
      }
    }

    if (!found){
      throw new PlayerSelectionException("Error selected player is not in squad");
    }
  }

  public PlayingSide playing_side()
  {
    return side;
  }
}
